package tcp_net.mail.pop3.commands;

import tcp_net.mail.MailBoxFileManager;
import tcp_net.mail.pop3.commands.debug.DebugInfo;

import tcp_net.mail.pop3.states.*;
import java.util.List;
import java.util.ArrayList;

/**
	This class provides a defined command to be executed
	@author J. Okuno
*/
public class QUIT extends POP3Command 
{
	/**
		Debug information
	*/
	private final static boolean DEBUG = DebugInfo.QUIT_DEBUG;
	
	/**
		A POP3 state
	*/
	private POP3State state;
	
	/**
		Init the class
		@param st a pop3 state object
		@param man a mailbox file manager
	*/
	public QUIT(POP3State st, MailBoxFileManager man) 
	{ 
		super(man);
		state = st;
	}
	
	/**
		This method executes a defined command
		@return a list of reply messages in a string format
	*/
	public List<String> execute() 
	{
		String state_info = "Unknown";
		if(state instanceof Update)
		{
			//manager.deleteMarkedMessages();
			state_info = "Update";
		}
		else if(state instanceof Authorization)
		{
			state_info = "Authorization";
		}
		else if(state instanceof Transaction)
		{
			manager.deleteMarkedMessages();
			state_info = "Transaction";
		}
		
		DebugInfo.print(DEBUG,"POP3 QUIT execute(): "+ state_info);
			
		//reply
		reply = new POP3ReplyMessage(true);
		reply_msgs.add(reply.execute().get(0));
		
		//Update State, an error message must be written. 
		
		return reply_msgs;
	}
}